﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Threading.Tasks;

namespace Thunder
{/// <summary>
/// plane
/// </summary>
    class plane
    {
        public Rectangle Rec;
        private const int Step = 30;
        ///绘制plane 
        ///
        ///
        public plane()
        {
            Rec = new Rectangle(450, 600, 120, 80);
        }
        public void Draw(Graphics g)
        {
            g.DrawImage(Properties.Resources.plane_I,Rec);
        }
        /// <summary>
        /// Plane移动
        /// </summary>
        /// <param name="key"></param>
        public void KeyDown(string key)
        {
            int NewX = Rec.X;
            int NewY = Rec.Y;

            if (key=="A")
            {
                //防止左出界
                NewX -= Step;
                if (NewX<0)
                {
                    NewX = 0;
                }
            }
            if (key == "D")
            {
                NewX += Step;
                //防止右出界
                if (NewX>900)
                {
                    NewX = 900;
                }
            }
            
                Rec = new Rectangle(NewX,
                    Rec.Y,
                    Rec.Width,
                    Rec.Height);
            

            if (key == "W")
            {
                NewY -= Step;
                //防止上出界
                if (NewY<0)
                {
                    NewY = 0;
                }
            }
            if (key == "S")
            {
                NewY += Step;
                //防止下出界
                if (NewY>630)
                {
                    NewY = 630;
                }
            }
            Rec = new Rectangle(Rec.X,
                    NewY,
                    Rec.Width,
                    Rec.Height);
        }
    }
}
